<?php
define("DSN","mysql:host=localhost;dbname=lab20");
define("DB_USER", "root");
define("DB_PSWD", "123456");

$name = $_GET['term'];
$name = "%".$name."%";
try{
	$pdo = new PDO(DSN, DB_USER, DB_PSWD);
	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$pdo->exec("set names utf8");
}
catch(Exception $e){
	echo $e->getMessage();
}

try{
	$stmt = $pdo->prepare("SELECT name AS label FROM `HotGoods` WHERE name LIKE :name");
	$stmt->bindParam(":name", $name);
	$stmt->execute();
	$goods = $stmt->fetchAll(PDO::FETCH_ASSOC);
	echo json_encode($goods);
}
catch(PDOException $e){
	echo $e->getMessage();
}